<?php

namespace App\Console\Commands;

use App\model\panyuan\MyApply;
use App\model\panyuan\UserShenheLog;
use App\model\User;
use Illuminate\Console\Command;

class MyApplyCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'myApply:name';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '修正myAppaly 关系';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        MyApply::chunk(100,function ($myapply){
            foreach ($myapply as $item){
                $usershenhe=UserShenheLog::with('user')->where('code',$item->code)->orderBy('id','desc')->first();
                if ($usershenhe&&$usershenhe->user->role_id==1){
                    if ($usershenhe->status==UserShenheLog::STATUS_PASS){
                        $item->last_status=MyApply::SHENHE_YEWU_PULISHED;
                    }
                    if ($usershenhe->status==UserShenheLog::STATUS_REJECT){
                        $item->last_status=MyApply::SHENHE_YEWU_REFUSE;
                    }
                }else{
                    $item->last_status=$item->status;

                }
                $item->save();
            }
        });
    }
}
